import { TagTypes } from "../type";
import { IInfo, IAction } from "./tag.type";

const initTag: IInfo = {
    tagList: [],//tag标签页面
}
//处理tag标签的 添加与移除
export const TagList = (state: IInfo = initTag, action: IAction) => {
    let { type } = action;
    let list = state.tagList;
    switch (type) {
        case TagTypes.ADD_TAG:
            const index = state.tagList.findIndex(
                (item) => item.path == action.route.path
            );
            if (index == -1) {
                list.push({
                    ...action.route,
                });
            }
            return { ...state, tagList: list };
        case TagTypes.REMOVE_TAG:
            const removeIndex = list.findIndex((item) => item.path == action.route.path);
            if (removeIndex != -1) {
                list.splice(removeIndex, 1);
            }
            return { ...state, tagList: list };
        default:
            return state
    }
}